﻿using Estsh.Core.Wms.IServices;
using Estsh.Core.Model.Result;
using Microsoft.AspNetCore.Mvc;
using Estsh.Core.Models;
using Estsh.Core.Controllers;
using Microsoft.AspNetCore.Authorization;
using Newtonsoft.Json.Linq;
using Estsh.Core.Model.Extend;
using Microsoft.AspNetCore.Mvc.Rendering;
using System.Reflection;
using Estsh.Core.Model.Extend.IFModels;
using Org.BouncyCastle.Asn1.Ocsp;
using Estsh.Core.Model.Extend.Models;

namespace Estsh.Core.Web.Areas.Wms.Controllers.ERPInterface
{
    [Route("wms/[controller]")]
    [ApiController]
    public class ERPInterfaceController : WmsBaseController
    {
        private IERPInterfaceService service;

        // GET: LoginController
        public ERPInterfaceController(IERPInterfaceService _service)
        {
            service = _service;
        }


        [HttpPost("GetInvokInterfaceData")]
        [AllowAnonymousAttribute]
        public IActionResult GetInvokInterfaceData([FromBody] ActionMessage actionMessage)
        {
            return InvokeMethod(actionMessage);
        }
        //[HttpPost("GetEquipReqIFConfig")]
        //[AllowAnonymousAttribute]
        private sys_if_rec_config GetEquipReqIFConfig(string code)
        {
            return service.GetEquipReqIFConfig(code);
        }
        /// <summary>
        /// 方法调度
        /// </summary>
        /// <param name="actionMsg">数据模型</param>
        /// <param name="IsReprocessing">预留字段</param>
        /// <param name="ReprocessingResult">1、存储返回结果，0不存储</param>
        /// <param name="handleOutput">处理后缀，去掉代码相关附加信息</param>
        /// <returns></returns>
        //[HttpPost("InvokeMethod")]
        //[AllowAnonymousAttribute]
        private IActionResult InvokeMethod(ActionMessage actionMsg, bool IsReprocessing = false, int ReprocessingResult = 0, bool handleOutput = false)
        {
            try
            {
                //先检查一下这个任务是不是已经正确完成了。如果正确完成了，直接返回正确的信号给客户端。

                sys_if_rec_config config = GetEquipReqIFConfig(actionMsg.Code.ToString());
                if (config == null)
                {
                    throw new Exception("EquipReqIFConfig没有找到配置代码:" + actionMsg.Code.ToString());
                }
                Type? type = Type.GetType(config.HandlerClass);
                object[] parameters = new object[1];
                parameters[0] = service;

                object? obj = Activator.CreateInstance(type, parameters);

                PropertyInfo[] objPros = type.GetProperties();

                object[] methodParams = new object[1];

                MethodInfo? method = type.GetMethod(config.HandlerMethod);

                if (method == null)
                {
                    throw new Exception("未找到相应的方法！" + config.HandlerMethod);
                }
                Type t = method.GetParameters()[0].ParameterType;
                //Type t2 = method.GetParameters()[1].ParameterType;

                //actionMsg.RequestData = JsonHelper.HandleInput(actionMsg.Code, actionMsg.RequestData.ToString()).Trim();

                var objModel = Newtonsoft.Json.JsonConvert.DeserializeObject(actionMsg.RequestData.ToString(), t);
                //var newObjModel = Convert.ChangeType(objModel, t);

                //methodParams[0] = actionMsg;
                methodParams[0] = objModel;
                try
                {
                    //实例化模型
                    object? result = method.Invoke(obj, methodParams);


                    IActionResult? res = (IActionResult)result;
                    if (handleOutput)
                    {
                        //res.Data = JsonHelper.HandleOutput(res.Code, res.Data.ToString());

                    }
                    return res;
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        throw ex.InnerException;
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #region 主数据

        /// <summary>
        /// 从SAP传递物料基本信息到WMS
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("MaterialMasterMethod")]
        [AllowAnonymousAttribute]
        public IActionResult MaterialMasterMethod(WmsInterfaceRequest<SapPtInterface_Extend> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                string ss = Newtonsoft.Json.JsonConvert.SerializeObject(responseData);
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (string.IsNullOrEmpty(sid))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }

                    List<SapPtInterface_Extend> sapPtInterfaces = responseData.objModel;

                    result = service.MaterialMasterMethod(sid, sapPtInterfaces);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// 从SAP传递供应商基本信息到WMS
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("SupplierMasterMethod")]
        [AllowAnonymousAttribute]
        public IActionResult SupplierMasterMethod(WmsInterfaceRequest<SapSuInterface> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapSuInterface> objModel = responseData.objModel;
                    result = service.SupplierMasterMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// 从SAP传递客户基本信息到WMS
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("CustomerMasterMethod")]
        [AllowAnonymousAttribute]
        public IActionResult CustomerMasterMethod(WmsInterfaceRequest<SapCuInterface> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapCuInterface> objModel = responseData.objModel;
                    result = service.CustomerMasterMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// 从SAP传递物料号与客户物料号对照信息到WMS
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("CustomerItemMasterMethod")]
        [AllowAnonymousAttribute]
        public IActionResult CustomerItemMasterMethod(WmsInterfaceRequest<SapPtcptInterface> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapPtcptInterface> objModel = responseData.objModel;
                    result = service.CustomerItemMasterMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// MBOM同步到MES系统
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("BomMasterMethod")]
        [AllowAnonymousAttribute]
        public IActionResult BomMasterMethod(WmsInterfaceRequest<SapBomInterface_Extend> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapBomInterface_Extend> objModel = responseData.objModel;
                    result = service.BomMasterMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// 设备主数据
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("EquipmentDataMethod")]
        [AllowAnonymousAttribute]
        public IActionResult EquipmentDataMethod(WmsInterfaceRequest<SapEquipment> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapEquipment> objModel = responseData.objModel;
                    result = service.EquipmentDataMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// 设备主数据
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("EquipmentPdLineDataMethod")]
        [AllowAnonymousAttribute]
        public IActionResult EquipmentPdLineDataMethod(WmsInterfaceRequest<SapEquipmentPdLine> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapEquipmentPdLine> objModel = responseData.objModel;
                    result = service.EquipmentPdLineDataMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// 部门主数据
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("DepartmentDataMethod")]
        [AllowAnonymousAttribute]
        public IActionResult DepartmentDataMethod(WmsInterfaceRequest<SapDepartment> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapDepartment> objModel = responseData.objModel;
                    result = service.DepartmentDataMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// 人员信息
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("ERPUserDataMethod")]
        [AllowAnonymousAttribute]
        public IActionResult ERPUserDataMethod(WmsInterfaceRequest<SapUser> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapUser> objModel = responseData.objModel;
                    result = service.ERPUserDataMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        #endregion

        #region ASN PO
        /// <summary>
        /// SAP系统把ASN传递到WMS用于采购收货
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("ASNDataMethod")]
        [AllowAnonymousAttribute]
        public IActionResult ASNDataMethod(WmsInterfaceRequest<SapAsnInterface> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapAsnInterface> objModel = responseData.objModel;
                    result = service.ASNDataMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// WMS中对 SA/PO 进行条码展开并打印的业务数据表
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("PODataMethod")]
        [AllowAnonymousAttribute]
        public IActionResult PODataMethod(WmsInterfaceRequest<SapDspoInterface_Extend> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapDspoInterface_Extend> objModel = responseData.objModel;
                    result = service.PODataMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        #endregion

        #region 
        /// <summary>
        /// SAP系统将一定期间内待发运交货单信息发布到WMS用于后续捡配发货
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("SalesAndDeliveryPlanMethod")]
        [AllowAnonymousAttribute]
        public IActionResult SalesAndDeliveryPlanMethod(WmsInterfaceRequest<SapDnInterface> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapDnInterface> objModel = responseData.objModel;
                    result = service.SalesAndDeliveryPlanMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// SAP把物料的零星出(入）指令传到WMS
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("SporadicEntryAndExitMethod")]
        [AllowAnonymousAttribute]
        public IActionResult SporadicEntryAndExitMethod(WmsInterfaceRequest<SapMiscoInterface> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapMiscoInterface> objModel = responseData.objModel;
                    result = service.SporadicEntryAndExitMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// 盘点开始时，SAP冻结库存，并把盘点表传到WMS
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("InventoryListMethod")]
        [AllowAnonymousAttribute]
        public IActionResult InventoryListMethod(WmsInterfaceRequest<SapCycoInterface> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapCycoInterface> objModel = responseData.objModel;
                    result = service.InventoryListMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// SAP把盘点差异转移到差异库的结果传到WMS，使得WMS可以根据盘点结果调整库存
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("InventoryDifferenceAdjustmentMethod")]
        [AllowAnonymousAttribute]
        public IActionResult InventoryDifferenceAdjustmentMethod(WmsInterfaceRequest<SapDifoInterface> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapDifoInterface> objModel = responseData.objModel;
                    result = service.InventoryDifferenceAdjustmentMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        #endregion

        #region 盘点


        #endregion

        #region  质检结果
        [HttpPost("QCMethod")]
        [AllowAnonymousAttribute]
        public IActionResult QCMethod(WmsInterfaceRequest<WmsToqce> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<WmsToqce> objModel = responseData.objModel;
                    result = service.QCMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        #endregion

        #region  工作中心
        /// <summary>
        /// 对应的工作中心相关的信息
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("WorkCenter")]
        [AllowAnonymousAttribute]
        public IActionResult WorkCenterMethod(WmsInterfaceRequest<SapWorkcenter> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapWorkcenter> objModel = responseData.objModel;
                    result = service.WorkCenterMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        #endregion

        #region  工序信息
        /// <summary>
        /// 工厂的现有的工艺信息
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("ProcessInfo")]
        [AllowAnonymousAttribute]
        public IActionResult ProcessInfoMethod(WmsInterfaceRequest<SapProcessinfo> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapProcessinfo> objModel = responseData.objModel;
                    result = service.ProcessInfoMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        #endregion

        #region  库存信息
        [HttpPost("StockInfo")]
        [AllowAnonymousAttribute]
        public IActionResult StockInfoMethod(WmsInterfaceRequest<SapStockinfo> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapStockinfo> objModel = responseData.objModel;
                    result = service.StockInfoMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        #endregion

        #region  物流公司
        [HttpPost("WmsLogistics")]
        [AllowAnonymousAttribute]
        public IActionResult WmsLogistics(WmsInterfaceRequest<WmsLogistics> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<WmsLogistics> objModel = responseData.objModel;
                    result = service.LogisticsMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        #endregion

        #region  人员信息
        [HttpPost("PersonMethod")]
        [AllowAnonymousAttribute]
        public IActionResult PersonMethod(WmsInterfaceRequest<WmsPerson> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<WmsPerson> objModel = responseData.objModel;
                    result = service.PersonMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        #endregion

        #region  仓库信息
        [HttpPost("WareHouseMethod")]
        [AllowAnonymousAttribute]
        public IActionResult WareHouseMethod(WmsInterfaceRequest<WmsWh> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<WmsWh> objModel = responseData.objModel;
                    result = service.WareHouseMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        #endregion

        #region APS接口
        /// <summary>
        /// 物料组主数据
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("MaterialGroupMethod")]
        [AllowAnonymousAttribute]
        public IActionResult MaterialGroupMethod(WmsInterfaceRequest<SapwlGroup> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapwlGroup> objModel = responseData.objModel;
                    result = service.MaterialGroupMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// 工艺主数据
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("RouttingMethod")]
        [AllowAnonymousAttribute]
        public IActionResult RouttingMethod(WmsInterfaceRequest<SapRouting> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapRouting> objModel = responseData.objModel;
                    result = service.RouttingMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        /// <summary>
        /// 工种主数据
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("WorkItemMethod")]
        [AllowAnonymousAttribute]
        public IActionResult WorkItemMethod(WmsInterfaceRequest<SapWorkItem> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapWorkItem> objModel = responseData.objModel;
                    result = service.WorkItemMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }


        /// <summary>
        /// 预测单
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("CalculateOrderMethod")]
        [AllowAnonymousAttribute]
        public IActionResult CalculateOrderMethod(WmsInterfaceRequest<SapCalculate> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapCalculate> objModel = responseData.objModel;
                    result = service.CalculateOrderMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        /// <summary>
        /// 月度评审结果
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("MonthReviewResultMethod")]
        [AllowAnonymousAttribute]
        public IActionResult MonthReviewResultMethod(WmsInterfaceRequest<SapMonthReviewResult> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapMonthReviewResult> objModel = responseData.objModel;
                    result = service.MonthReviewResultMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        /// <summary>
        /// 销售订单
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("SalesOrderDateMethod")]
        [AllowAnonymousAttribute]
        public IActionResult SalesOrderDateMethod(WmsInterfaceRequest<SapSalessOrder> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapSalessOrder> objModel = responseData.objModel;
                    result = service.SalesOrderDateMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        /// <summary>
        /// 销售订单评审结果
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("SalesReviewResultMethod")]
        [AllowAnonymousAttribute]
        public IActionResult SalesReviewResultMethod(WmsInterfaceRequest<SapSalesReviewResult> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapSalesReviewResult> objModel = responseData.objModel;
                    result = service.SalesReviewResultMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        /// <summary>
        /// 采购申请
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("PurachasesReqMethod")]
        [AllowAnonymousAttribute]
        public IActionResult PurachasesReqMethod(WmsInterfaceRequest<SapPurchasesReq> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapPurchasesReq> objModel = responseData.objModel;
                    result = service.PurachasesReqMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// 销售订单审批结果通知
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("SapSalesReviewNoticeMethod")]
        [AllowAnonymousAttribute]
        public IActionResult SapSalesReviewNoticeMethod(WmsInterfaceRequest<SapSalesReviewNotice> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapSalesReviewNotice> objModel = responseData.objModel;
                    result = service.SapSalesReviewNoticeMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        /// <summary>
        /// 采购订单
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        [HttpPost("PurachasesMethod")]
        [AllowAnonymousAttribute]
        public IActionResult PurachasesMethod(WmsInterfaceRequest<SapPurchases> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapPurchases> objModel = responseData.objModel;
                    result = service.PurachasesMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        /// <summary>
        /// 亿日 SAP把物料的零星出(入）指令传到WMS扩展
        /// 增加了关联订单号和部门
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("SporadicEntryAndExitExtendMethod")]
        [AllowAnonymousAttribute]
        public IActionResult SporadicEntryAndExitExtendMethod(WmsInterfaceRequest<SapMiscoInterface_Extend> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapMiscoInterface_Extend> objModel = responseData.objModel;
                    result = service.SporadicEntryAndExitExtendMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        /// <summary>
        /// 销售历史数据
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("SalesHistoryMethod")]
        [AllowAnonymousAttribute]
        public IActionResult SalesHistoryMethod(WmsInterfaceRequest<SapSalesHistory> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapSalesHistory> objModel = responseData.objModel;
                    result = service.SalesHistoryMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        /// <summary>
        /// 发货通知单
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("SalesAndDeliveryPlanExtendMethod")]
        [AllowAnonymousAttribute]
        public IActionResult SalesAndDeliveryPlanExtendMethod(WmsInterfaceRequest<SapDnInterface_Extend> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<SapDnInterface_Extend> objModel = responseData.objModel;
                    result = service.SalesAndDeliveryPlanExtendMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        #endregion
        #region  仓位信息
        [HttpPost("ZoneMethod")]
        [AllowAnonymousAttribute]
        public IActionResult ZoneMethod(WmsInterfaceRequest<WmsZone> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    string sid = responseData.sid;
                    if (sid.Equals(""))
                    {
                        result.success = false;
                        result.message = "sid不能为空";
                        return Json(result);
                    }
                    if (responseData.objModel.Count == 0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }
                    List<WmsZone> objModel = responseData.objModel;
                    result = service.ZoneMethod(sid, objModel);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }
        #endregion

    }
}
